<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../react18/react.development.js"></script>
    <script src="../react18/react-dom.development.js"></script>
    <script src="../react18/babel.min.js"></script>
</head>
<body>
    <div id="app"></div>
    <script type="text/babel">
   class Child extends React.Component{
    state={
            b:2
        }
        static getDerivedStateFromProps(props,state){
            const {a,count} = props;
            return {myA:a}
        }
        shouldComponentUpdate() {
          console.log("shouldComponentUpdate");
          return true;
        }
        render(){
            return <div>
                <h2>Child组件{this.props.count}</h2>
                </div>
        }
        componentDidUpdate() {
          console.log("子组件componentDidUpdate");
        }
        componentDidMount(){
            console.log("子组件初始化渲染");
        }
   }
   class App extends React.Component{
    state={
        count:0
    }
    static getDerivedStateFromProps(props,state){
        console.log("父组件getDerivedStateFromProps");
        const { a } = props;
        return { myA: a };
    }
    render() {
          console.log("-----render-----");
          const { count } = this.state;
          return (
            <div>
              <Child a="1" count={count} />
              <h2>App组件:{count}</h2>
              <button
                onClick={() => {
                  this.setState({ count: count + 1 });
                }}
              >
                count累加
              </button>
            </div>
          );
        }
        getSnapshotBeforeUpdate() {
          console.log("getSnapshotBeforeUpdate");
          return null;
        }
        componentDidUpdate() {
          console.log("父组件componentDidUpdate");
        }
   }
   ReactDOM.createRoot(document.getElementById("app")).render(<App />);
    </script>
</body>
</html>